package com.example.ssm.controller;

import com.example.ssm.entity.User;
import com.example.ssm.service.ShopService;
import com.example.ssm.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/admin")
public class AdminController {
    @Resource
    UserService userService;
    ShopService shopService;
    @RequestMapping("/search")
    public String search(User user, HttpSession session,Model model) throws IOException {
        System.out.println(user);
        List<User> list=new ArrayList<User>();
        if (!user.getUname().equals("")&&!user.getPhonenumber().equals("")){
            System.out.println("uname+phonenumber+Permission");
            list=userService.selectLikeUnamePhonenumberPermission(user);
            model.addAttribute("User",list);
        }
        else if(!user.getUname().equals("")&&user.getPhonenumber().equals("")){
            System.out.println("uname+Permission");
            list=userService.selectLikeUnamePermission(user);
            model.addAttribute("User",list);
        }
        else if(user.getUname().equals("")&&!user.getPhonenumber().equals("")){
            System.out.println("phonenumber+Permission");
            list=userService.selectLikePermissionphonenumber(user);
            model.addAttribute("User",list);
        }else if(user.getUname().equals("")&&user.getPhonenumber().equals("")){
            System.out.println("Permission");
            list=userService.selectLikePermission(user);
            model.addAttribute("User",list);
        }

        return "admin";
    }

}
